<?php
/**
 * Personal cart
 * 
 */ 
 
 if(isset($_POST['submit'])){
    
    $aVals = $_POST['val'];
    foreach($aVals as $key => $aVal){
        //update soluong
        $_SESSION['cart'][$key]['soluong'] = $aVal['soluong'];
      if(isset($aVal['delete'])){
        unset($_SESSION['cart'][$aVal['delete']]);
      }  
    }
 }

//var_dump ($_SERVER);die('453534');
if(!isset($_SESSION['cart']) || count($_SESSION['cart'])==0 ){
    echo 'Chưa có sản phẩm trong giỏ hàng';
}else{
?>
<div id="main-content">
<h1>giỏ hàng của bạn</h1>
<form id="cart" method="post" action="<?php echo DOMAIN_NAME ?>/page/cart">
<table class="cart" border="1" cellpadding="5" cellspacing="5">
    <tr>
        <th></th>
        <th>Hình ảnh</th>
        <th>Tên sản phẩm</th>
        <th>Số lượng</th>
        <th>Giá sản phẩm</th>
        <th>Thành tiền</th>
    </tr>
    <?php foreach($_SESSION['cart'] as $item){        
 //       echo '<tr>
//                <td >
//                    <a href="javascript:removeProduct('.$item['id'].')" class="delete" title="delete">Delete</a>
//                    <a href="javascript:updateCart($(this));" class="update" title="delete">Update</a>
//                </td>
//                <td><div class="image"><img src="'.PRODUCT_IMAGE_URL.$item['hinh_anh'].'" alt="'.$item['hinh_anh'].'" /></div></td>
//                <td><a href="#" >'.$item['ten_san_pham'].'</a></td>
//                <td><input type="text" value="'.$item['soluong'].'"/></td>
//                <td>'.$item['gia'].'</td>
//              </tr>';

       echo '<tr>
                <td >
                    <input type="checkbox" value="'.$item['id'].'" name="val['.$item['id'].'][delete]" />
                </td>
                <td><div class="image"><img src="'.PRODUCT_IMAGE_URL.$item['hinh_anh'].'" alt="'.$item['hinh_anh'].'" /></div></td>
                <td><a href="#" >'.$item['ten_san_pham'].'</a></td>
                <td><input type="text" value="'.$item['soluong'].'" name="val['.$item['id'].'][soluong]"/></td>
                <td>'.$item['gia'].'</td>
                <td>'.$item['gia']*$item['soluong'].'</td>
              </tr>';
    }?>
    <tr>
        <td colspan="6">
            <input type="submit" value="Cập nhật" name="submit" />
            <input type="button" value="Thanh toán" onclick="window.location.href='/chuotlenshop/page/checkout';" />
        </td>
    </tr>
</table>

</form>
</div>
<?php    
}
?>